package com.ace3l.legal.gwt.domainmodule.client;

import com.synesthesiaconsulting.gwt.resources.client.DirectorUnit;
import com.synesthesiaconsulting.gwt.resources.client.GWTActionUnitFactory;
import com.synesthesiaconsulting.gwt.resources.client.IActionUnit;
import com.synesthesiaconsulting.gwt.resources.client.GWTUtils;
import com.google.gwt.core.client.GWT;

/**
 * Created by IntelliJ IDEA.
 * User: ageer
 * Date: Jul 24, 2008
 * Time: 7:14:06 PM
 * To change this template use File | Settings | File Templates.
 */
public class NavDirector {
    //public static NavDirector singleton = new NavDirector();

    private DirectorUnit base;
    private String gwtBase = "/gwt";
    private String portalBase;
    private String homePage = "homeportal.Ace3LPortal";

    public NavDirector() {
        String moduleBaseUrl = GWT.getModuleBaseURL();
        portalBase = moduleBaseUrl.substring(0, moduleBaseUrl.indexOf(gwtBase)+4);
        base = new DirectorUnit();
        addModule(homePage);
    }

    public String makeUrlForModule(String moduleName) {
        return portalBase+"/"+GWTUtils.packageToUrl(moduleName);
    }

    public DirectorUnit addModule(String modName) {
        return base.addSubModule(modName,GWTActionUnitFactory.makeGWTNavigationUnit(makeUrlForModule(modName)));
    }
    public void goToModule(String moduleName) {
        base.applyAction(moduleName+".$SELF");
    }
    public void applyActionTo(String action, Object object) {
        base.applyActionTo(action, object);
    }
    public void performAction(String action) {
        base.applyAction(action);
    }
    
    public DirectorUnit getDirector() { return base; }
    public DirectorUnit getDirector(String id) { return (DirectorUnit)base.getDirector(id); }
}
